package com.fhzn.auth.entity;

import lombok.Data;

import java.io.Serializable;

/**
 * 泛化返回结果
 *
 * @param <T>
 * @author fhzn
 */
@Data
public class Result<T> implements Serializable {

    /**
     * 结果
     */
    private boolean success;

    /**
     * 错误提示
     */
    private String errMsg;

    /**
     * 实际返回数据
     */
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setData(data);
        result.setSuccess(true);
        return result;
    }

    public static <T> Result fail(String errMsg) {
        Result result = new Result<>();
        result.setSuccess(false);
        result.setErrMsg(errMsg);
        return result;
    }

    public boolean isFail() {
        return !success;
    }
}

